// 忽略掉各种SVG的组件
import { defineAsyncComponent, AsyncComponentLoader, ComputedOptions, MethodOptions } from 'vue';
export const components =
				 import.meta.glob(['/src/components/**/*.vue', '!/src/components/customComponents/icon/svg/**/*.vue']);
/**
 * 获取组件的实例
 * @param path 组件的实际路径
 */
export const getComponent = (path: string | undefined): any => {
	// 判断访问的组件是否存在,如果不加判断,直接访问不存在的组件,
	// vue会爆炸,因此加入判断机制提升容错.
	if (path) {
		if (components[`/src/components/${path}.vue`]) {
			// 如果存在直接跳到该页面
			return defineAsyncComponent({
				loader           : components[`/src/components/${path}.vue`] as AsyncComponentLoader<any>,
				delay            : 200,
				loadingComponent : components[`/src/components/customComponents/loading/Windows11Loading.vue`],
				timeout          : 5000,
				errorComponent   : components[`/src/components/errorPage/error.vue`]
			});
		} else {
			// 如果不存在则跳到404页面
			return defineAsyncComponent({
				loader           : components[`/src/components/errorPage/404.vue`] as AsyncComponentLoader<any>,
				delay            : 200,
				loadingComponent : components[`/src/components/customComponents/loading/Windows11Loading.vue`],
				timeout          : 5000,
				errorComponent   : components[`/src/components/errorPage/error.vue`]
			});
		}
	} else {
		// 如果不存在则跳到404页面
		return defineAsyncComponent({
			loader           : components[`/src/components/errorPage/404.vue`] as AsyncComponentLoader<any>,
			delay            : 200,
			loadingComponent : components[`/src/components/customComponents/loading/Windows11Loading.vue`],
			timeout          : 5000,
			errorComponent   : components[`/src/components/errorPage/error.vue`]
		});
	}
};